package cn.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import cn.dto.Message;
import cn.dto.PageInfo;
import cn.dto.Result;
import cn.dto.common;
import cn.pojo.Category;
import cn.service.CategoryService;
import cn.service.impl.CategoryServiceImpl;

/**
 * Servlet implementation class CategoryServlet
 */
@WebServlet("/deleteCategoryServlet")
public class deleteCategoryServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private CategoryService categoryService = new CategoryServiceImpl();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取参数
		String postdata = common.getPostData(request.getInputStream(), request.getContentLength(), null);
		Integer addCagetoryparam = Integer.parseInt(postdata);
		Integer id = addCagetoryparam;
		Boolean flag = categoryService.deleteCategory(id);
		Result result = new Result();
		if(flag == true) {
			Message message = new Message(200,"删除成功");
			result.setMessage(message);
		}else {
			Message message = new Message(400,"删除失败");
			result.setMessage(message);
		}
		response.getWriter().write(JSON.toJSONString(result));
	}

}
